<?php
class ControllerReportProductViewed extends AdminController {
	public function index() {

		$this->document->setTitle($this->_['heading_title']);

		M('report/product');

		$product_viewed_total = $this->model_report_product->getTotalProductsViewed();

		$product_views_total = $this->model_report_product->getTotalProductViews();

		$this->data['products'] = array();

		$qf = new Query_filter();
		$results = $this->model_report_product->getProductsViewed($qf);

		foreach ($results as $result) {
			if ($result['viewed']) {
				$percent = round($result['viewed'] / $product_views_total * 100, 2);
			} else {
				$percent = 0;
			}

			$this->data['products'][] = array(
				'name'    => $result['name'],
				'model'   => $result['model'],
				'viewed'  => $result['viewed'],
				'percent' => $percent . '%'
			);
		}

		$this->data['reset'] = UA('report/product_viewed/reset');

		$this->data['pagination'] = $this->pagination($product_viewed_total)->render();

		$this->display('report/product_viewed.tpl');
	}

	public function reset() {

		M('report/product');

		$this->model_report_product->reset();

		$this->session->set_flashdata('success', $this->_['text_success']);

		$this->redirect(UA('report/product_viewed'));
	}
}
?>